package code.D1222;

/**
 * author： yeswater
 * create： 2023/12/22
 * <p>
 * 目标和
 */
public class T494 {
    public int findTargetSumWays(int[] nums, int target) {
        return dfs(nums, target, 0, 0);
    }
    
    // dfs 就是递归
    int dfs(int[] nums, int target, int u, int cur) { // u 是什么？ 数值下标
        if (u == nums.length) {
            return cur == target ? 1 : 0;
        }
        int left = dfs(nums, target, u + 1, cur + nums[u]);
        int right = dfs(nums, target, u + 1, cur - nums[u]);
        return right + left;
    }
}
